(function (vc, vm) {

    vc.extends({
        data: {
            editShopSettingInfo: {
                ssId: '',
                shopId: '',
                settingName: '',
                settingType: '',
                settingKey: '',
                settingValue: '',
                remark: '',
            }
        },
        _initMethod: function () {

        },
        _initEvent: function () {
            vc.on('editShopSetting', 'openEditShopSettingModal', function (_params) {
                $that.refreshEditShopSettingInfo();
                $('#editShopSettingModel').modal('show');
                vc.copyObject(_params, $that.editShopSettingInfo);
                $that.editShopSettingInfo.caId = vc.getCurrentCommunity().caId;
            });
        },
        methods: {
            editShopSettingValidate: function () {
                return vc.validate.validate({
                    editShopSettingInfo: $that.editShopSettingInfo
                }, {
                   
                    'editShopSettingInfo.settingName': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "名称不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "64",
                            errInfo: "名称不能超过64"
                        },
                    ],
                    'editShopSettingInfo.settingKey': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "设置key不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "30",
                            errInfo: "设置key不能超过30"
                        },
                    ],
                    'editShopSettingInfo.settingValue': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "设置值不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "255",
                            errInfo: "设置值不能超过255"
                        },
                    ],
                    'editShopSettingInfo.remark': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "备注信息不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "512",
                            errInfo: "备注信息不能超过512"
                        },
                    ]

                });
            },
            editShopSetting: function () {
                if (!$that.editShopSettingValidate()) {
                    vc.toast(vc.validate.errInfo);
                    return;
                }

                vc.http.apiPost(
                    '/shopSetting/updateShopSetting',
                    JSON.stringify($that.editShopSettingInfo),
                    {
                        emulateJSON: true
                    },
                    function (json, res) {
                        //vm.menus = vm.refreshMenuActive(JSON.parse(json),0);
                        let _json = JSON.parse(json);
                        if (_json.code == 0) {
                            //关闭model
                            $('#editShopSettingModel').modal('hide');
                            vc.emit('shopSettingManage', 'listShopSetting', {});
                            return;
                        }
                        vc.toast(_json.msg);
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');

                        vc.toast(errInfo);
                    });
            },
            refreshEditShopSettingInfo: function () {
                $that.editShopSettingInfo = {
                    ssId: '',
                    shopId: '',
                    settingName: '',
                    settingType: '',
                    settingKey: '',
                    settingValue: '',
                    remark: '',
                }
            }
        }
    });

})(window.vc, window.$that);
